<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Maps extends CI_Controller {
	public $key;

	function __controller() {
		parent::Controller();

	}

	public function index($page = 0) {
		echo '[{}]';
	}

	public function city($region) {
		# поиск города  в регионе   &format=json&
	}

	public function street($region = 1) {

		$this -> load -> model('Adsent_modul', 'adsent');
		$street = $this -> input -> post('street');
		$code = $this -> input -> post('code');

		echo json_decode($respon);
	}

	/*
	 public function street($region = 1) {

	 $this -> load -> model('Adsent_modul', 'adsent');
	 $something = $this -> input -> post('input');
	 $r = $this -> adsent -> region($region);
	 $data = $r['name'] . ',' . $something;
	 $data = $something;
	 $respon = $this -> url($data);
	 #	echo json_decode($respon);
	 }
	 */

	public function moskow() {
		$this -> load -> model('Adsent_modul', 'adsent');

		$something = $this -> input -> post('input');
		$data = 'город Москва,' . $something;

		echo $respon = $this -> url($data);

	}

	public function url($request = 'улица') {

		$arr = false;

		$format = 'format=json&';
		# &locality=москва
		#		sll	37.643695000000015,55.80424550197424
		$format = '&results=1&ll=37.643695000000015,55.80424550197424&ыpn=0.833332,0.530138&rspn=0&';
		$this -> key = 'ADvWGFABAAAASwkMTwIAsHoMAnDWW80CWMZnXrEB0hgKksQAAAAAAAAAAABBWwFnq2ESo-cr7ggavsWSyhVomg==';
		$dop = 'geocode=' . $request . '' . $format . $this -> key;

		$url = 'http://geocode-maps.yandex.ru/1.x/';

		$url = 'http://maps.yandex.ru/';
		$dop = 'text=' . $request . '&rspn=1&sll=37.643695000000015%2C55.80424550197424&sspn=0.020170%2C0.002103&z=16&type=geo&source=form&output=json';

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		// set url to post to
		curl_setopt($ch, CURLOPT_FAILONERROR, 1);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
		// allow redirects
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		// return into a variable
		curl_setopt($ch, CURLOPT_TIMEOUT, 3);
		// times out after 4s
		curl_setopt($ch, CURLOPT_POST, 1);
		// set POST method
		curl_setopt($ch, CURLOPT_POSTFIELDS, $dop);
		// add POST fields
		$result = curl_exec($ch);
		// run the whole process
		curl_close($ch);

		echo $url . '?' . $dop;
		return $result;
	}

	/*
	 * curpos	37.609218-55.753559
	 id_source	Thoroughfare
	 llspn	&results=1&ll=37.609218,55.752655&spn=0.833332,0.530138&rspn=0
	 target	Thoroughfare_select
	 text	Р РѕСЃСЃРёСЏ, РњРѕСЃРєРІР°,
	 text2	РєСѓР»Р°РєРѕРІ
	 *
	 */
}

/*
 http://maps.yandex.ru/services/search/1.x/search.json?
 lang=ru-RU&ll=37.66627810616481%2C55.99086603146204&origin=maps-form&results=3
 &spn=1.2908935546875213%2C0.1616445395648185&
 text=%D0%BF%D0%B0%D0%BD%D1%84%D1%91%D1%80%D0%BE%D0%B2%D0%B0&type=geo%2Cpsearch&z=10

 http://maps.yandex.ru/?text=&sll=37.643695000000015%2C55.80424550197424&sspn=0.020170%2C0.002103&z=16&type=geo&source=form&output=json

 */
